const router = require("express").Router();
const { body, param } = require("express-validator");
const validate = require("../middleware/validate");
const { auth } = require("../middleware/auth");
const ctrl = require("../controllers/comment.controller");

// 获取某篇文章的评论
router.get(
    "/post/:postId",
    [param("postId").isMongoId()],
    validate,
    ctrl.listComments
);

// 发表评论（需登录）
router.post(
    "/post/:postId",
    auth(true),
    [param("postId").isMongoId(), body("content").isLength({ min: 1 })],
    validate,
    ctrl.createComment
);

// 删除评论（作者或管理员）
router.delete(
    "/:id",
    auth(true),
    [param("id").isMongoId()],
    validate,
    ctrl.deleteComment
);

module.exports = router;
